home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / v7n13.arc / COPROCES.PAS < prev    next >
Pascal/Delphi Source File  |  1988-05-18  |  5KB  |  142 lines

  1.  
  2. PROGRAM Coprocessor_Clock;
  3.   {$V-,C-}  {NOTE These two compiler switches are ESSENTIAL\}
  4. TYPE
  5.   AnyString = STRING[255];
  6.  
  7. VAR
  8.   PresentColor,
  9.   PresentBackGround : Byte;      {global variables for colour control}
  10.   Hour, Min, Sec    : Byte;      {global variables for clock control}
  11.   TheString         : AnyString;      
  12.   Count             : Byte;      {global variables for main program}
  13.  
  14.   PROCEDURE SetColor(F, B : Byte);
  15.   BEGIN
  16.     PresentColor := F;        {remember the colour settings}
  17.     PresentBackGround := B;
  18.     TextColor(F);             {and implement them}
  19.     TextBackground(B);
  20.   END;
  21.  
  22.   PROCEDURE Clock;            { clock display }
  23.   TYPE
  24.     RegPack = RECORD
  25.                 CASE Integer OF
  26.                   1 : (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags : Integer);
  27.                   2 : (AL, AH, BL, BH, CL, CH, DL, DH : Byte);
  28.               END;
  29.   VAR
  30.     ColumnHold, RowHold, ColorHold, BackGrndHold : Byte;
  31.     Tmp : STRING[2];
  32.     Time : STRING[8];
  33.     Regs : RegPack;
  34.  
  35.   BEGIN
  36.     WITH Regs DO
  37.       BEGIN                   {get time from msdos}
  38.         AH := $2C;          {call the clock interrupt}
  39.         MsDos(Regs);
  40.         {did the time change ? }
  41.         IF (CH <> Hour) OR (CL <> Min) OR (DH <> Sec) THEN
  42.         {delete the (DH <> Sec) if you don't want seconds display}
  43.           BEGIN
  44.             Hour := CH;       {save the new time}
  45.             Min := CL;
  46.             Sec := DH;        {delete if you dont want seconds display}
  47.             RowHold := WhereY; {save the present cursor position}
  48.             ColumnHold := WhereX;
  49.             ColorHold := PresentColor; {save the present colour}
  50.             BackGrndHold := PresentBackGround;
  51.             Str(Hour:2, Tmp);
  52.             Time := Tmp;
  53.             Str(Min:2, Tmp);
  54.             Time := Time+':'+Tmp;
  55.             Str(Sec:2, Tmp);  {delete if you dont want seconds display}
  56.             Time := Time+':'+Tmp; {delete if you dont want seconds display}
  57.             GoToXY(70, 1);    {go and display the time}
  58.             SetColor(LightCyan, Black);
  59.             Write(Time);
  60.             GoToXY(ColumnHold, RowHold); {restore the cursor position}
  61.             SetColor(ColorHold, BackGrndHold); {and the colour}
  62.           END;
  63.       END;
  64.   END;
  65.  
  66.   FUNCTION KeyInCoprocess : Char;
  67.     { get characters from the keyboard }
  68.   VAR
  69.     KeyToGet : Char;
  70.   BEGIN                            {if no key pressed then do something else}
  71.     WHILE NOT KeyPressed DO Clock; {it does not have to be just the clock}
  72.     Read(Kbd, KeyToGet);
  73.     KeyInCoprocess := KeyToGet;
  74.   END;
  75.  
  76.   PROCEDURE NewRead(VAR StringToGet : AnyString);
  77.   {This procedure replaces the 'Read' procedure to read a string.  It would
  78.    require modification if you want to input integers or reals directly.}
  79.   VAR
  80.     CharacterIn, Discard : Char;
  81.   CONST
  82.     Return = ^M;
  83.     BackSpace = ^H;
  84.     Space = ' ';
  85.     Escape = ^[;
  86.     Beep = ^G;
  87.  
  88.   BEGIN
  89.     StringToGet := '';        {clear the string}
  90.     REPEAT
  91.       CharacterIn := KeyInCoprocess; {get a key if one is ready}
  92.       CASE CharacterIn OF     {check what sort of key}
  93.         ' '..'z' : BEGIN {'Normal' character. - you can select any 
  94.                          acceptable range of characters here}
  95.                      Write(CharacterIn); {write it}
  96.                      StringToGet := StringToGet+CharacterIn; 
  97.                      {append it to the string}
  98.                    END;
  99.         BackSpace : IF StringToGet[0] > #0 THEN
  100.                       BEGIN
  101.                         StringToGet[0] := Pred(StringToGet[0]); 
  102.                         {remove the last character from the string}
  103.                         Write(BackSpace); {backspace on the screen}
  104.                         Write(Space);     {write a blank}
  105.                         Write(BackSpace); {and backspace again}
  106.                       END;
  107.         Escape : BEGIN
  108.                    IF KeyPressed THEN Discard := KeyInCoprocess;
  109.                    {you could implement something with the cursor
  110.                     or function keys here.}
  111.                  END;
  112.         Return : ;   {don't do anything}
  113.       ELSE Write(Beep);       {tells you if you typed something odd}
  114.       END;
  115.     UNTIL (CharacterIn = Return) OR (StringToGet[0] = #255);
  116.     {repeat until return is typed or the string overflows}
  117.   END;
  118.  
  119. BEGIN                         {main program}
  120.   SetColor(Red, White);
  121.   ClrScr;
  122.   GoToXY(70, 2);  Write('+---+--+');
  123.   FOR Count := 3 TO 9 DO
  124.     BEGIN
  125.       GoToXY(74, Count);  Write('|');
  126.     END;
  127.   GoToXY(29, 10);  Write('Testing Clock Routine -----------------------+');
  128.   GoToXY(20, 15);  Write('Take about a minute to enter this message');
  129.   GoToXY(25, 16);  Write('and watch the clock being updated.');
  130.   GoToXY(1, 12);   SetColor(Black, White);
  131.   Write('+------------------------------ Input a String');
  132.   Write(' -------------------------------+');
  133.   GoToXY(1, 13);  SetColor(Yellow, White);
  134.   NewRead(TheString);
  135.   GoToXY(1, 20);  SetColor(Black, Magenta);
  136.   Write('+------------------------------ The String Was');
  137.   Write(' -------------------------------+');
  138.   GoToXY(1, 21);     SetColor(Black, White);
  139.   Write(TheString);  GotoXY(1,24);
  140. END.
  141.  
  142.